package ink.lovejinhu.leetcodeMatch;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @Author: jin
 * @Date: 2021/8/29 10:54
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_5855 {
    public String kthLargestNumber(String[] nums, int k) {
        if (k > nums.length) {
            return "";
        }
        Arrays.sort(nums, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                if (o1.length() > o2.length()) {
                    return 1;
                } else if (o1.length() == o2.length()) {
                    for (int i = 0; i < o1.length(); i++) {
                        if (o1.charAt(i) > o2.charAt(i)) {
                            return 1;
                        } else if (o1.charAt(i) == o2.charAt(i)) {
                            continue;
                        } else {
                            return -1;
                        }
                    }
                    return 0;

                } else {
                    return -1;
                }

            }
        });

        return nums[nums.length - k];
    }
}
